package ru.onlinestore.mobile.data.repository

import ru.onlinestore.mobile.core.Response
import ru.onlinestore.mobile.data.sources.ProductsRemoteSource
import ru.onlinestore.mobile.domain.entities.ProductDomain
import ru.onlinestore.mobile.domain.entities.ProductListDomain
import ru.onlinestore.mobile.domain.repository.ProductsRepository

class ProductsRepositoryImpl(
    private val remote: ProductsRemoteSource
): ProductsRepository {
    override suspend fun fetchProductList(): Response<ProductListDomain> {
        val productList = remote.fetchProductList()

        return productList.map { list ->
            ProductListDomain(
                products = list.products.map { product ->
                    ProductDomain(
                        id = product.id,
                        title = product.title,
                        description = product.description,
                        price = product.price,
                        brand = product.brand ?:"",
                        category = product.category,
                        thumbnail = product.thumbnail,
                        images = product.images
                    )
                },
                total = list.total,
                skip = list.skip,
                limit = list.limit
            )
        }
    }

}